<template>
	<view>
		<view class="edit-box">
			<view class="textarea-box">
				<textarea class="textarea" :placeholder="placeholder" :auto-focus="true" :maxlength="maxlength" v-model="content"></textarea>
			</view>
			<view class="tips-box">
				<text>{{content.length}}</text>/{{maxlength}}
			</view>
		</view>
		<btnTpl @confirmEvent="handleCheckThreeLevel">保存</btnTpl>
	</view>
</template>

<script>
	import btnTpl from '../../components/recruit/btn-tpl.vue'

	export default {
		data() {
			return {
				placeholder: '等待输入内容...',
				content: '',
				fieldName: '',
				maxlength: 140
			}
		},
		components: {
			btnTpl
		},
		onLoad(options) {
			let type = options.type,
				title = '编辑个人信息',
				maxlength = 140;
			switch (type) {
				case 'moreDemand':
					title = '其他需求'
					maxlength = 140
					break;
				case 'jobContent':
					title = '工作内容'
					maxlength = 140
					break;
				case 'explored':
					title = '自我评价'
					maxlength = 140
					break;
				case 'jobDemand':
					title = '职位要求'
					maxlength = 800
			}
			uni.setNavigationBarTitle({
				title: title
			});
			this.maxlength = maxlength
			this.fieldName = type
			this.content = uni.getStorageSync(type)
		},
		onUnload() {
			let _this = this;
			uni.removeStorageSync(_this.fieldName)
		},
		methods: {
			handleCheckThreeLevel() {
				let pages = getCurrentPages(),
					prevPage = pages[pages.length - 2]; //-2为上一级页面  
				prevPage.$vm[this.fieldName] = this.content
				 
				uni.navigateBack({
					delta: 1 // delta: 1返回上一级（A 页面）    delta: 2返回上两级
				})
			}
		}
	}
</script>

<style lang="less">
	.edit-box {
		border-top: 1rpx solid #C7BEBE;
		padding: 30rpx;
	}

	.textarea {
		width: 100%;
		font-size: 26rpx;
		height: 360rpx;
	}

	.tips-box {
		border-top: 1rpx solid rgba(0, 0, 0, 0.08);
		margin-top: 30rpx;
		padding: 20rpx 0;
		font-size: 24rpx;
		text-align: right;

		text {
			color: #00B6E9;
		}
	}
</style>
